﻿//********************************************************************************//
//创建日期：<创建日期，2017-11-13>
//创建作者：<郭登杰>
//功能说明：计划指标注销费用列表
//********************************************************************************//

using System;
using System.Data;
using System.Web.UI;
using BLL.Access;
using Entity;
using Web.Class;

namespace Web.Controls
{
    public partial class UCLHShenQingXX_JHZBZX : UserControl, IUCLHOperate
    {
        #region 事件

        /// <summary>
        ///     页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) InitControl();
        }

        #endregion

        #region 属性

        /// <summary>
        ///     记录查询结果集
        /// </summary>
        private DataTable dtSource
        {
            get { return ViewState["dtSource"] as DataTable; }
            set { ViewState["dtSource"] = value; }
        }

        /// <summary>
        ///     来函类型
        /// </summary>
        public eLaiHanLX LaiHanLX { get; set; }

        /// <summary>
        ///     来函流程步骤
        /// </summary>
        public eLaiHanLCBH LaiHanLC
        {
            get
            {
                return ViewState["LaiHanLC"] == null
                    ? eLaiHanLCBH.未登记
                    : (eLaiHanLCBH) Enum.Parse(typeof(eLaiHanLCBH), Convert.ToString(ViewState["LaiHanLC"]));
            }
            set { ViewState["LaiHanLC"] = value.ToString(); }
        }

        /// <summary>
        ///     设置复选框列显隐
        /// </summary>
        public bool ShowCheck;

        /// <summary>
        ///     记录来函编号
        /// </summary>
        public string LaiHanBH
        {
            get { return Convert.ToString(ViewState["LaiHanBH"]); }
            set { ViewState["LaiHanBH"] = value; }
        }

        /// <summary>
        ///     设置列表高度
        /// </summary>
        public int ListHeight
        {
            set { gvList.Settings.VerticalScrollableHeight = value; }
        }

        #endregion

        #region 方法

        /// <summary>
        ///     配置控件
        /// </summary>
        public void InitControl()
        {
        }

        /// <summary>
        ///     重新绑定
        /// </summary>
        public void BindData()
        {
            var amount = 0.0;
            foreach (DataRow row in dtSource.Rows)
            {
                amount += Convert.ToDouble(row["N_HEXIAOJE"]);
            }

            labelAmount.Text = amount.ToString();
            gvList.DataSource = dtSource;
            gvList.DataBind();
            /*
            //控制复选框列
            for (int i = 0; i < this.gvList.VisibleRowCount; i++)
            {
                ASPxCheckBox cb = (ASPxCheckBox)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "cb");
                cb.Visible = ShowCheck;
            }
             * */
        }

        /// <summary>
        ///     清空数据
        /// </summary>
        public void ClearInfo()
        {
            dtSource = null;
            gvList.DataSource = null;
            gvList.DataBind();
        }

        /// <summary>
        ///     验证
        /// </summary>
        /// <returns></returns>
        public ValidateRS Validate()
        {
            var rs = new ValidateRS();
            if (dtSource == null || dtSource.Rows.Count == 0)
            {
                rs.Msg = "请查询出要注销的费用。";
                return rs;
            }

            rs.IsSuccess = true;
            return rs;
        }

        /// <summary>
        ///     根据来函加载信息
        /// </summary>
        /// <param name="laihanxx"></param>
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            if (laihanxx.ID == 0)
            {
                LaiHanLC = eLaiHanLCBH.未登记;
                if (string.IsNullOrEmpty(laihanxx.S_YONGHUBH)) return;

                if (laihanxx.S_YONGHUBH.Length == 6) laihanxx.S_YONGHUBH = "0" + laihanxx.S_YONGHUBH;
            }
            else
            {
                LaiHanLC = (eLaiHanLCBH) Enum.Parse(typeof(eLaiHanLCBH), laihanxx.I_LIUCHENGBH.ToString());
            }

            dtSource = new SpHelper().P_YSLH_JIHUAZBZXXXHQ(laihanxx.S_LAIHANBH, laihanxx.S_YONGHUBH,
                (int) (laihanxx.I_TZY * 100 + laihanxx.I_TZM)).Tables[0];
            BindData();
        }

        /// <summary>
        ///     获取申请信息
        /// </summary>
        /// <returns></returns>
        public void CreateShengQingXX(YS_LH_LAIHANXX laihanxx)
        {
            var bllT = new YS_LH_JIHUAZBZXXXProcess();
            bllT.DeleteYS_LH_JIHUAZBZXXXesDynamic("S_LAIHANBH=" + laihanxx.S_LAIHANBH);
            for (var i = 0; i < gvList.VisibleRowCount; i++)
            {
                var obj = new YS_LH_JIHUAZBZXXX();
                var vals = (object[]) gvList.GetRowValues(i, "I_FEIYONGBH", "S_YONGHUH", "I_YM", "N_JIAJIAJE",
                    "N_YINGSHOUJE", "N_SHISHOUJE", "N_QIANFEIJE", "N_HEXIAOJE");
                obj.I_FEIYONGBH = Convert.ToDecimal(vals[0]);
                obj.S_YONGHUH = Convert.ToString(vals[1]);
                obj.I_YM = Convert.ToInt32(vals[2]);
                obj.N_JIAJIAJE = Convert.ToDecimal(vals[3]);
                obj.N_YINGSHOUJE = Convert.ToDecimal(vals[4]);
                obj.N_SHISHOUJE = Convert.ToDecimal(vals[5]);
                obj.N_QIANFEIJE = Convert.ToDecimal(vals[6]);
                obj.N_HEXIAOJE = Convert.ToDecimal(vals[7]);
                obj.S_LAIHANBH = laihanxx.S_LAIHANBH;
                obj.I_JLZT = 0;
                obj.ID = 0;
                bllT.InsertOrUpdate(obj);
            }
        }

        #endregion
    }
}